import axios from "./axios.js";
import Qs from 'qs';
// login页面api
export function login(data) {
	return axios({
		method: "get",
		params: {
			_gp: "admin",
			_mt: "login",
			...data
		}
	});
}

// 角色页面api
export function role(query) {
	return axios({
		method: "get",
		params: {
			_gp: "admin.role",
			_mt: "list",
			...query
		}
	});
}
export function addRole(query) {
	return axios({
		method: "get",
		params: {
			_gp: "admin.role",
			_mt: "create",
			role: query
		}
	});
}
export function editRole(query) {
	return axios({
		method: "get",
		params: {
			_gp: "admin.role",
			_mt: "update",
			role: query
		}
	});
}
export function deleteRole(query) {
	return axios({
		method: "post",
		params: {
			_gp: "admin.role",
			_mt: "delete",
			roleId: query
		}
	});
}
export function getPermission(query) {
	return axios({
		method: "get",
		params: {
			_gp: "admin.role",
			_mt: "permissionList",
			roleId: query
		}
	});
}
export function updatePermission(query) {
	return axios({
		method: "post",
		data: Qs.stringify({
			_gp: "admin.role",
			_mt: "permissionSet",
			roleSetPermissionDTO: JSON.stringify(query)
		})
	});
}

export function optionsRole() {
	return axios({
		method: "get",
		params: {
			_gp: "admin.role",
			_mt: "options"
		}
	});
}

// 管理员api
export function admin(data) {
	return axios({
		method: "get",
		params: {
			_gp: "admin",
			_mt: "list",
			...data
		}
	});
}
export function addAdmin(data) {
	return axios({
		method: "post",
		data: Qs.stringify({
			_gp: "admin",
			_mt: "create",
			adminDTO: JSON.stringify(data)
		})
	});
}
export function updateAdmin(data) {
	return axios({
		method: "post",
		data: Qs.stringify({
			_gp: "admin",
			_mt: "update",
			adminDTO: JSON.stringify(data)
		})
	});
}
export function deleteAdmin(data) {
	return axios({
		method: "post",
		params: {
			_gp: "admin",
			_mt: "delete",
			id: data
		}
	});
}
// 会员管理
export function usermansge(data) {
	return axios({
		method: "get",
		params: {
			_gp: "admin.user",
			_mt: "getUser",
			...data
		}
	});
}
export function createUser(data) {
	return axios({
		method: "post",
		params: {
			_gp: "admin.user",
			_mt: "addUser",
			user: JSON.stringify(data)
		}
	});
}
export function updateUser(data) {
	return axios({
		method: "post",
		params: {
			_gp: "admin.user",
			_mt: "updateUser",
			user: JSON.stringify(data)
		}
	});
}
export function deleteUser(id, nickname) {
	return axios({
		method: "post",
		params: {
			_gp: "admin.user",
			_mt: "deleteUser",
			id: id,
			nickname: nickname
		}
	});
}
export function setUser(data) {
	return axios({
		method: "post",
		params: {
			_gp: "admin.user",
			_mt: "updateStatus",
			userId: data.id,
			status: data.status
		}
	});
}

// 商铺信息
const uploadPath = "http://192.168.1.54:8081/upload/admin";
export {
	uploadPath
};

export function getShop() {
	return axios({
		method: "get",
		params: {
			_gp: "admin.merchant",
			_mt: "getMerchant",
		}
	});
}

export function updateShop(data) {
	return axios({
		method: "post",
		data: Qs.stringify({
			_gp: "admin.merchant",
			_mt: "updateMerchant",
			...data
		})
	});
}

// 优惠劵
export function getCoupon(data) {
	return axios({
		method: "get",
		params: {
			_gp: "admin.coupon",
			_mt: "queryCouponByTitle",
			...data
		}
	});
}

export function setCouponStatus(data) {
	return axios({
		method: "post",
		data: Qs.stringify({
			_gp: "admin.coupon",
			_mt: "updateCouponStatus",
			...data
		})
	});
}

export function deleteCoupon(data) {
	return axios({
		method: "get",
		params: {
			_gp: "admin.coupon",
			_mt: "deleteCoupon",
			...data
		}
	});
}


export function createCoupon(data) {
	return axios({
		method: "post",
		data: Qs.stringify({
			_gp: "admin.coupon",
			_mt: "addCoupon",
			...data
		})
	});
}
export function getCategory() {
	return axios({
		method: "get",
		params: {
			_gp: "admin.category",
			_mt: "categoryTree"
		}
	});
}
export function updateCoupon(data) {
	return axios({
		method: "post",
		data: Qs.stringify({
			_gp: "admin.coupon",
			_mt: "updateCoupon",
			...data
		})
	});
}
// 推荐管理
export function getRecommend(data) {
	return axios({
		method: 'get',
		params: {
			_gp: "admin.recommend",
			_mt: "queryRecommendByType",
			...data
		}
	})
}

export function createRecommend(data) {
	return axios({
		method: 'post',
		data: Qs.stringify({
			_gp: "admin.recommend",
			_mt: "addRecommend",
			...data
		})
	})
}

export function getSpuBigTree() {
	return axios({
		method: 'get',
		params: {
			_gp: "admin.goods",
			_mt: "getSpuBigTree",
		}

	})
}
export function deleteRecommend(query, spuId) {
	return axios({
		method: 'post',
		data: Qs.stringify({
			_gp: "admin.recommend",
			_mt: "deleteRecommend",
			recommendType: query,
			id: spuId
		})

	})
}
// 商铺广告
export function getAdvert(data) {
	return axios({
		method: 'get',
		params: {
			_gp: "admin.advertisement",
			_mt: "queryAdvertisement",
			...data
		}
	})
}

export function deleteAdvert(type, id) {
	return axios({
		method: 'get',
		params: {
			_gp: "admin.advertisement",
			_mt: "deleteAdvertisement",
			adType: type,
			adId: id
		}
	})
}
export function getAdCategory() {
	return axios({
		method: 'get',
		params: {
			_gp: "admin.goods",
			_mt: "getSpuBigTree",
		}
	})
}

export function createAdvert(data) {
	return axios({
		method: 'post',
		data: Qs.stringify({
			_gp: "admin.advertisement",
			_mt: "addAdvertisement",
			...data
		})
	})
}
export function updateAdvert(data) {
	return axios({
		method: "post",
		data: Qs.stringify({
			_gp: "admin.advertisement",
			_mt: "updateAdvertisement",
			...data,
			adId: data.id
		})
	});
}

// 订单管理
export function getOrderList(data) {
	return axios({
		method: 'get',
		params: {
			_gp: "admin.order",
			_mt: "list",
			...data
		}
	})
}
export function getOrderDetail(id) {
	return axios({
		method: 'get',
		params: {
			_gp: "admin.order",
			_mt: "detail",
			orderId: id
		}
	})
}

export function editAdminMono(id, adminLevel, adminMono) {
	return axios({
		method: 'get',
		params: {
			_gp: "admin.order",
			_mt: "editAdminMono",
			orderId: id,
			level: adminLevel,
			mono: adminMono
		}
	})
}
export function ship(data) {
	return axios({
		method: 'get',
		params: {
			'_gp': "admin.order",
			'_mt': "ship",
			...data
		}
	})
}
export function setRefund(data) {
	return axios({
		method: 'get',
		params: {
			'_gp': "admin.order",
			'_mt': "refund",
			...data
		}
	})
}
export function queryToExcel(data) {
	return axios({
		method: 'get',
		params: {
			'_gp': "admin.order",
			'_mt': "queryToExcel",
			...data
		}
	})
}

export function statisticsToExcel(start, end) {
	return axios({
		method: 'get',
		params: {
			'_gp': "admin.order",
			'_mt': "statistics",
			'gmtStart': start,
			'gmtEnd': end
		}
	})
}

// 运费模板
export function getFreightList() {
	return axios({
		method: 'get',
		params: {
			_gp: "admin.freight",
			_mt: "getAllFreightTemplate"
		}
	})
}

export function deletaFreight(id) {
	return axios({
		method: 'post',
		params: {
			_gp: "admin.freight",
			_mt: "deleteFreightTemplate",
			templateId: id
		}
	})
}

export function createFreight(data) {
	return axios({
		method: 'post',
		data: Qs.stringify({
			_gp: "admin.freight",
			_mt: "addFreightTemplate",
			...data,
			freightTemplateCarriageDOList: JSON.stringify(
				data.freightTemplateCarriageDOList
			)
		})
	})
}

export function updateFreight(data) {
	return axios({
		method: 'post',
		data: Qs.stringify({
			_gp: "admin.freight",
			_mt: "updateFreightTemplate",
			...data,
			freightTemplateCarriageDOList: JSON.stringify(
				data.freightTemplateCarriageDOList
			)
		})
	})
}
// 商品类目
export function getCategoryList(data) {
	return axios({
		method: 'get',
		params: {
			_gp: "admin.category",
			_mt: "queryCategory",
			...data
		}
	})
}
export function getCategoryTree() {
	return axios({
		method: 'get',
		params: {
			_gp: "admin.category",
			_mt: "categoryTree"
		}
	})
}
export function getcategorySecondTree() {
	return axios({
		method: 'get',
		params: {
			_gp: "admin.category",
			_mt: "categorySecondLevelTree"
		}
	})
}

export function deleteCategory(categoryId) {
	return axios({
		method: 'post',
		params: {
			_gp: "admin.category",
			_mt: "deleteCategory",
			id: categoryId
		}
	})
}
export function addCategory(data) {
	return axios({
		method: 'post',
		data: Qs.stringify({
			_gp: "admin.category",
			_mt: "addCategory",
			...data
		})
	})
}

export function updateCategory(data) {
	return axios({
		method: 'post',
		data: Qs.stringify({
			_gp: "admin.category",
			_mt: "updateCategory",
			...data
		})
	})
}

// 商品列表
export function getGoodsList(data) {
	return axios({
		method: 'get',
		params: {
			_gp: "admin.goods",
			_mt: "list",
			...data
		}
	})
}

export function deleteGoods(id) {
	return axios({
		method: 'post',
		params: {
			_gp: "admin.goods",
			_mt: "delete",
			spuId: id
		}
	})
}
export function setGoodsStatus(id, statusText) {
	return axios({
		method: 'get',
		params: {
			_gp: "admin.goods",
			_mt: "freezeOrActivation",
			spuId: id,
			status: statusText
		}
	})
}
export function getGoodsDetail(id) {
	return axios({
		method: 'get',
		params: {
			_gp: "admin.goods",
			_mt: "detail",
			spuId: id
		}
	})
}
export function batchDeleteGoods(id) {
	return axios({
		method: 'post',
		data: Qs.stringify({
			_gp: "admin.goods",
			_mt: "batchDelete",
			ids: JSON.stringify(id)
		})
	})
}

export function editGoods(data) {
  return axios({
    method: "post",
    data: Qs.stringify({
      _gp: "admin.goods",
      _mt: "edit",
      spuDTO: JSON.stringify(data)
    })
  });
}
export function createGoods(data) {
  return axios({
    method: "post",
    data: Qs.stringify({
      _gp: "admin.goods",
      _mt: "create",
      spuDTO: JSON.stringify(data)
    })
  });
}
export function tinymceImg(data) {
  return axios({
    url: uploadPath,
    method: "post",
    data
  });
}
//首页
export function info() {
	return axios({
		method: 'get',
		params: {
			_gp: "admin.dashboard",
			_mt: "integral",
		}
	})
}
// 评论管理
export function getAppraise(data) {
	return axios({
		method: 'get',
		params: {
			_gp: "admin.appraise",
			_mt: "getAppraiseList",
			...data
		}
	})
}

export function deleteAppraise(data) {
	return axios({
		method: 'get',
		params: {
			_gp: "admin.appraise",
			_mt: "deleteAppraise",
			...data
		}
	})
}